<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .body{
            height: 2000px;
            overflow: scroll;
        }
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
            margin-top: 100px;

        }
        .box2{
            width: 100px;
            height: 100px;
            background-color: blue;
            margin-top: 100px;
        }


    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <script>
        const io=new IntersectionObserver((entries)=>{
            console.log(entries);
            
        },{
            threshold:[0,0.5,1],//表示观察的元素与窗口交叉的状态为这个阈值时，才会触发观察
            // root:document.querySelector('.container')//表示监听目标元素与该父容器的交叉状态
        })
        io.observe(document.querySelector('.box1'))
    </script>
</body>
</html>